/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.camachosanchez.gui.textfield;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.Paint;
import java.awt.RenderingHints;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;

/**
 *
 * @author GTEPERU02
 */
public class JERoundTextField extends JTextField {

    private int arcw = 24;
    private int arch = 24;
    private Image image = null;
    private Icon icon;
    private Color fondo;

    public JERoundTextField() {
        setOpaque(false);
        setBorder(new EmptyBorder(0, 5, 0, 2));
        setPreferredSize(new Dimension(100, 20));
        fondo = Color.white;
    }

    public void setFondo(Color fondo) {
        this.fondo = fondo;
    }

    @Override
    protected void paintComponent(Graphics g) {

        Graphics2D g2 = (Graphics2D) g;
        Paint oldPaint = g2.getPaint();
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2.setColor(fondo);
        g2.fillRect(0, 0, getWidth(), getHeight());
        g2.setPaint(new GradientPaint(0.0f, 0.0f, Color.BLACK, 0.0f, getHeight(), Color.BLACK));
        g2.setColor(Color.white);
        g2.fillRoundRect(0, 0, getWidth() - 1, getHeight() - 1, arcw, arch);
        g2.setColor(new Color(102, 155, 199));
        g2.drawRoundRect(0, 0, getWidth() - 1, getHeight() - 1, arcw, arch);

        if (getImage() != null) {
            g2.drawImage(getImage(), 5, 3, null);
            setBorder(new EmptyBorder(0, (int) (getHeight() * 1.2), 0, 2));
        } else {
            setBorder(new EmptyBorder(0, (int) (getHeight() * 0.5), 0, 2));
        }

        g2.setPaint(oldPaint);
        super.paintComponent(g);

    }

    public int getArcw() {
        return arcw;
    }

    public void setArcw(int arcw) {
        this.arcw = arcw;
    }

    public int getArch() {
        return arch;
    }

    public void setArch(int arch) {
        this.arch = arch;
    }

    public Image getImage() {
        return image;
    }

    public void setImage(Image image) {
        this.image = image;
    }

    public Icon getIcon() {
        return icon;
    }

    public void setIcon(Icon icon) {
        this.icon = icon;
        setImage(((ImageIcon) icon).getImage());
    }
}
